﻿using AbpDemo.EntityConfig;
using Microsoft.EntityFrameworkCore;

namespace Chen.IdentityServer4.DbAll
{
    public class RightDbContext : DbContext
    {
        /// <summary>
        /// 用户
        /// </summary>
        public DbSet<SysUser> SysUsers { get; set; }
        public DbSet<SysuserRole> SysuserRoles { get; set; }
        /// <summary>
        /// 角色
        /// </summary>
        public DbSet<SysRole> SysRoles { get; set; }
        /// <summary>
        /// 菜单表
        /// </summary>
        public DbSet<SysModule> SysModules { get; set; }
        public DbSet<ModuleAuthority> ModuleAuthorities { get; set; }


        public RightDbContext(DbContextOptions<RightDbContext> options)
    : base(options)
        {

        }

        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)

        {

            optionsBuilder.UseMySql("server=localhost;port=3306;Database=exam;Uid=root;Pwd=cjj.123456;charset=utf8mb4;");

        }


        protected override void OnModelCreating(ModelBuilder builder)
        {
            base.OnModelCreating(builder);

            /* Include modules to your migration db context */

            /* Configure your own tables/entities inside here */

            //builder.Entity<YourEntity>(b =>
            //{
            //    b.ToTable(AbpDemoConsts.DbTablePrefix + "YourEntities", AbpDemoConsts.DbSchema);
            //    b.ConfigureByConvention(); //auto configure for the base class props
            //    //...
            //});

            //注入所有的fluentapi 方式的配置
            builder.ApplyConfigurationsFromAssembly(typeof(SysModuleButtonConfig).Assembly);
            //builder.Entity<Rodman>(b =>
            //{
            //    b.ToTable(nameof(Rodman), AbpPermissionManagementDbProperties.DbSchema);

            //    b.ConfigureByConvention();

            //    b.Property(x => x.RodmanName).HasMaxLength(50).IsRequired();
            //    b.Property(x => x.RodmanAvg).HasMaxLength(500).IsRequired();

            //    b.Property(x => x.CreateBy).HasComment("创建人").IsRequired();
            //    b.Property(x => x.UpdateBy).HasComment("修改人");
            //    b.Property(x => x.CreateTime).HasComment("创建时间").IsRequired();
            //    b.Property(x => x.UpdateTime).HasComment("修改时间");
            //    b.Property(x => x.Status).HasComment("1正常 0已删除").IsRequired().HasDefaultValue(1);

            //    b.HasIndex(x => new { x.RodmanName });

            //    b.ApplyObjectExtensionMappings();
            //});

            //builder.Entity<SportBooking>(b =>
            //{
            //    b.ToTable(AbpDemoConsts.DbTablePrefix + nameof(SportBooking), AbpPermissionManagementDbProperties.DbSchema);

            //    b.ConfigureByConvention();
            //    b.Property(x => x.Id).HasComment("运动预约id").IsRequired();
            //    b.Property(x => x.BookingPrice).HasComment("预定价格").HasPrecision(18,2).IsRequired();
            //    b.Property(x => x.RodmanId).HasComment("rodmanid").IsRequired();
            //    b.Property(x => x.BookingTime).HasComment("预定时间").IsRequired();

            //    b.Property(x => x.CreateBy).HasComment("创建人").IsRequired();
            //    b.Property(x => x.UpdateBy).HasComment("修改人");
            //    b.Property(x => x.CreateTime).HasComment("创建时间").IsRequired();
            //    b.Property(x => x.UpdateTime).HasComment("修改时间");
            //    b.Property(x => x.Status).HasComment("1正常 0已删除").HasDefaultValue(1).IsRequired();

            //    b.ApplyObjectExtensionMappings();
            //});

        }
    }
}
